/**
 * 修改提现密码
 * @author  Jello
 * @create  2018/10/18 19:08
 * @version 1.0
 * @company 广东蓝聘科技网络有限公司
 **/
var spinner = new Spinner(opts);
var i = 0; //密码位数
var userid_sgin = "";

$(function() {

	userid_sgin = sessionStorage.getItem("userid_sign");
	if(!userid_sgin) {
		userid_sgin = sessionStorage.getItem("openid");
	}
	
	//数字显示隐藏
	$(".xiaq_tb").click(function() {
		$(".numb_box").slideUp(500);
	});
	$(".mm_box").click(function() {
		$(".numb_box").slideDown(500);
	});

	//提现密码身份校验
	$(".nub_ggg li .zf_num").click(function() {
		if(i < 6) {
			$(".mm_box li").eq(i).addClass("mmdd");
			$(".mm_box li").eq(i).attr("withpwd", $(this).text());
			i++;
			if(i == 6) {
				//判断本地存储密码次数为3次并且cookie中存储的值为null时,就把本地存储的次数清除(cookie10分钟失效后要把本地存储的密码次数删除)
				if(localStorage.getItem("sess_time_local") == 3 && $.cookie("sess_time_local") == null) {
					localStorage.removeItem("sess_time_local");
				}
				var sess_time = localStorage.getItem("sess_time_local"); //当前密码错误次数就等于本地存储的次数,牵扯到提现密码的页面都会记录并且每次叠加,直接赋值
				setTimeout(function() {
					var withpwd = "";
					$(".mm_box li").each(function() { //获取输入的密码
						withpwd += $(this).attr("withpwd");
					});
					if($.cookie("sess_time_local") == 3) { //密码错误次数过多
						$(".esc_divbox2").show();
						$(".esc_box2").show();
						return;
					} else {
						//校验提现密码接口上送
						var param = {};
						param.userid_sign = userid_sgin;
						param.type = 1;
						param.oldPwd = hex_md5(hex_md5(withpwd) + salt);
						param.withdrawPwd = "";
						checkWithdrawPwd(param, function(resultObj) {
							if(resultObj.code == 0 && resultObj.data == 1) {
								window.location.href = "withdrawpwd_upok.html";
							} else {
								//身份验证失败,记录错误提现密码次数
								sess_time++;
								localStorage.setItem("sess_time_local", sess_time);
								if(sess_time == 3) { //错误次数达到3次
									$(".esc_divbox2").show();
									$(".esc_box2").show();
									var date = new Date();
									date.setTime(date.getTime() + 60 * 1000 * 10); //过期为10分钟
									$.cookie("sess_time_local", sess_time, { //存储次数cookie
										expires: date,
										path: '/bluehired'
									});
								} else { //密码错误次数提醒
									$("#local_time").html((3 - sess_time));
									$(".esc_box").show();
									$(".esc_divbox").show();
								}
							}
						});
					}
				}, 100);
			}
		}
	})

	//密码删除
	$(".nub_ggg li .zf_del").click(function() {
		if(i > 0) {
			i--
			$(".mm_box li").eq(i).removeClass("mmdd");
			$(".mm_box li").eq(i).attr("withpwd", "");
		}
	});
	//密码清空
	$(".nub_ggg li .zf_empty").click(function() {
		$(".mm_box li").removeClass("mmdd");
		$(".mm_box li").attr("withpwd", "");
		i = 0;
	});

	//提现密码错误重试
	$("#retrybtn").click(function() {
		$(".esc_box").hide();
		$(".esc_divbox").hide();
		$(".mm_box li").removeClass("mmdd");
		$(".mm_box li").attr("withpwd", "");
		i = 0;
	});
	//	$(".esc_divbox").click(function() {
	//		$(".esc_box").hide();
	//		$(".esc_divbox").hide();
	//	})

	//返回个人中心
	$("#backpersion_page").click(function() {
		if(sessionStorage.getItem("wallet_sign") == 001166) {
			window.location.href = "../../wallet.html";
		} else if(sessionStorage.getItem("paycard_sign") == 001177) {
			window.location.href = "../../paycardmanager_grade.html";
		} else {
			window.location.href = "../../app/personal/personal.html";
		}
	})

	//短信验证方式
	$("#phoneMsg").click(function() {
		toPage(userid_sgin, "withdrawpwd_updatecode.html", "../../login.html");
	})

})